#ifndef CONIN_UI_MANAGER_IMPLEMENTATION_H
#define CONIN_UI_MANAGER_IMPLEMENTATION_H

#include "uimgr.h"
#include "window.h"
#include <windows.h>

namespace cnc {

	namespace ui {

		class ManagerImpl : public Services, public Manager
		{
			Window *window_;
			ManagerImpl() : window_(0) {}
		public:
			static ManagerImpl &instance()
			{
				static ManagerImpl object;
				return object;
			}
			virtual Services *getServices()
			{
				return this;
			}
		private: // Services
			virtual bool start()
			{
				if ((window_ = Window::instance()) == 0)
					return false;
				if (window_->create() == false)
					return false;
				return true;
			}
			virtual bool execute()
			{
				MSG message;
				if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {
					TranslateMessage(&message);
					DispatchMessage(&message);
					if (message.message == WM_QUIT)
						return false;
				}
				return true;
			}
			virtual bool stop()
			{
				return true;
			}
			virtual bool selectForm(const char *formID)
			{
				return window_->selectForm(formID);
			}
			virtual bool setInfo(const char *infoID, const char *utf8text)
			{
				return window_->setInfo(infoID, utf8text);
			}
		};

	} // namespace ui

} // namespace cnc

#endif
